Some(name.to_string())
} else {
// bin is either a source file or a directory with main.rs inside.
- if bin.ends_with("main.rs") {
+ if bin.ends_with("main.rs") && !bin.ends_with("src/bin/main.rs") {
if let Some(parent) = bin.parent() {
- // if the path ends with main.rs it is probably a directory, but it can also be
- // a file directly inside src/bin
- if parent.ends_with("src/bin") {
- // This will always return name "main"
- bin.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string())
- } else {
- parent.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string())
- }
+ // Use a name of this directory as a name for binary
+ parent.file_stem().and_then(|s| s.to_str()).map(|f| f.to_string())
} else {
None
}
// here we have a single bin, so it may be located in src/main.rs, src/foo.rs,
// src/bin/foo.rs, src/bin/foo/main.rs or src/bin/main.rs
if bin_len == 1 {
- let path = Path::new("src").join(&format!("main.rs"));
+ let path = Path::new("src").join("main.rs");
if package_root.join(&path).exists() {
return path.to_path_buf()
}
}
// check for the case where src/bin/foo/main.rs is present
- let path = Path::new("src").join("bin").join(bin.name()).join(&format!("main.rs"));
+ let path = Path::new("src").join("bin").join(bin.name()).join("main.rs");
if package_root.join(&path).exists() {
return path.to_path_buf()
}
- return Path::new("src").join("bin").join(&format!("main.rs")).to_path_buf()
+ return Path::new("src").join("bin").join("main.rs").to_path_buf()
}
// bin_len > 1
}
// we can also have src/bin/foo/main.rs, but the former one is preferred
- let path = Path::new("src").join("bin").join(bin.name()).join(&format!("main.rs"));
+ let path = Path::new("src").join("bin").join(bin.name()).join("main.rs");
if package_root.join(&path).exists() {
return path.to_path_buf()
}
}
}
- let path = Path::new("src").join("bin").join(&format!("main.rs"));
+ let path = Path::new("src").join("bin").join("main.rs");
if package_root.join(&path).exists() {
return path.to_path_buf()
}
- return Path::new("src").join(&format!("main.rs")).to_path_buf()
+ return Path::new("src").join("main.rs").to_path_buf()
}
fn build_profiles(profiles: &Option<TomlProfiles>) -> Profiles {